package com.pair.micro.common.constant;

import lombok.AllArgsConstructor;
import lombok.Getter;

/** 系统异常 以0开头 */
@Getter
@AllArgsConstructor
public enum MicroSystemError {
  SYS_00000("00000", "操作成功"),

  SYS_00001("00001", "操作失败"),
  SYS_00002("00002", "系统异常"),
  SYS_00003("00003", "未知错误"),
  SYS_00004("00004", "Session过期"),
  SYS_00005("00005", "Token过期"),
  SYS_00006("00006", "认证失败"),
  SYS_00007("00007", "DB操作失败"),
  SYS_00008("00008", "Cache操作失败"),
  SYS_00009("00009", "refresh_token 已失效"),

  SYS_00050("00050", "非法的调用请求"),
  SYS_00051("00051", "调用次数过于频繁"),
  SYS_00052("00052", "调用次数已达上限"),
  SYS_00055("00055", "您已被列入黑名单"),

  SYS_00071("00071", "网络通信异常"),
  SYS_00072("00072", "网络通信超时"),

  SYS_00081("00081", "无权访问"),
  SYS_00082("00082", "请求入参数据异常，请开发者自检"),
  SYS_00083("00083", "接口请求方式不正确"),
  SYS_00085("00085", "此接口不支持GET请求方式"),
  SYS_00086("00086", "此接口不支持POST请求方式"),

  SYS_00100("00100", "尽请期待"),
  SYS_00101("00101", "暂未开放"),
  SYS_00102("00102", "暂停服务"),

  SYS_00105("00105", "服务器停机更新中"),

  SYS_00200("00200", "调用summer系统Api失败"),
  SYS_00201("00201", "调用第三方Api失败"),
  SYS_00202("00202", "调用第三方Sdk失败"),

  SYS_00301("00301", "动态SQL执行失败，请检查SQL是否正确！"),
  SYS_00302("00302", "上传文件失败"),

  SYS_00303("00303", "上传文件失败，请检查配置信息"),


  SYS_99999("99999", "自定义异常");

  private String code;
  private String msg;

  /**
   * 根据编码查询异常信息
   *
   * @param code
   * @return
   */
  public static MicroSystemError getSysError(String code) {
    for (MicroSystemError jycloudSystemError : values()) {
      if (jycloudSystemError.getCode().equals(code)) {
        return jycloudSystemError;
      }
    }
    return null;
  }
}
